import { logger } from "./logger";
/**
 *
 * @param barkKey bark推送key
 * @returns 推送函数
 * @description 推送函数，用于发送消息
 */
export function createNotification(barkKey= process.env.APP_NOTICE_KEY) {
  async function sendMessage(message) {
    const url = `https://api.day.app/${barkKey}/${encodeURIComponent(
      message
    )}?icon=https://unpkg.com/@vbenjs/static-source@0.1.7/source/avatar-v1.webp`;
    try {
      const res = await fetch(url);
      const data = await res.json();
      if (data.code === 200) {
        logger("推送结果:" + data.message);
      }
    } catch (err) {
      logger("推送失败:" + err.message);
    }
  }
  return [sendMessage];
}
